<?php

use think\migration\Migrator;
use think\migration\db\Column;

class GoodsUnit extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('goods_unit', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '商品单位表']);
        $table->addColumn('name', 'string', ['default' => '', 'limit' => 50, 'comment' => '单位名称', 'after' => 'id'])
            ->addColumn('status', 'integer', ['default' => 1, 'limit' => 1, 'comment' => '状态：1正常，2禁用', 'after' => 'name'])
            ->addColumn('code', 'string', ['default' => '', 'limit' => 50, 'comment' => '单位编码', 'after' => 'status'])
            ->addColumn('sort', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '排序', 'after' => 'code'])
            ->addColumn('type', 'integer', ['default' => 1, 'limit' => 1, 'comment' => '类型：1小单位，2中单位，3大单位', 'after' => 'sort'])
            ->addColumn('create_time', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '创建时间', 'after' => 'type'])
            ->addColumn('update_time', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '更新时间', 'after' => 'create_time'])
            ->addColumn('delete_time', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '删除时间', 'after' => 'update_time'])
            ->create();
    }
}
